package com.xinsoft.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @className: TokenUtil
 * @author: wh
 * @date: 2021/2/21 11:14 上午
 */
public class TokenUtil {

    public static String getToken() {
        return JWTUtil.getTokenFromRequest(ServletUtils.getRequest());
    }

    public static TokenInfo getTokenInfo() {
        return JWTUtil.getTokenInfo(getToken());
    }

    /**
     * 获取当前登陆账户企业id
     *
     * @return
     */
    public static Integer getCompanyId() {
        return JWTUtil.getCompanyID(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));
    }

    /**
     * 获取当前登陆账户
     *
     * @return userId,username,relName,deptId
     */
    public static SysUser getUser() {
        HttpServletRequest request = ServletUtils.getRequest();
        if (request == null){
            return null;
        }else{
            return JWTUtil.getSysUser(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));
        }
    }


    /**
     * 获取当前登陆账户id
     *
     * @return
     */
    public static Integer getUserId() {
        return JWTUtil.getUserId(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));
    }

    /**
     * 获取当前登陆账户deptId
     *
     * @return
     */
    public static Integer getDeptId() {
        return JWTUtil.getDeptId(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));

    }

    /**
     * 获取当前登陆企业名称
     *
     * @return
     */
    public static String getCompanyName() {
        return JWTUtil.getCompanyName(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));

    }

    /**
     * 获取当前登账户用户名
     * @return
     */
    public static String getRealName() {
        return JWTUtil.getRealName(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));
       // return JWTUtil.getUsername(JWTUtil.getTokenFromRequest(ServletUtils.getRequest()));

    }
}
